﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;

namespace Inspire.Main.UIElements
{
    class NavButton : Button
    {
        // INavHost NavHostParent
        private INavHost NavHostParent;

        // Page to Load When Button is Clicked
        private string _NavPageUri = "";

        /// <summary>
        /// Returns the URI this button directs the user to when clicked.
        /// </summary>
        public string NavPageUri
        {
            get
            {
                return this._NavPageUri;
            }
        }

        /// <summary>
        /// Create a new Navigation Button.
        /// </summary>
        /// <param name="textLabel">Text to show on the button.</param>
        /// <param name="navPageUri">URI of Page the button will direct to.</param>
        /// <param name="styleName">Name of the style to apply to this new navigation button.</param>
        /// <param name="parent">INavHost parent that the navigation request will propogate to after this button is clicked.</param>
        public NavButton(string textLabel, string navPageUri, string styleName, INavHost parent)
        {
            // Set parameterized values
            this.Content = textLabel;
            this._NavPageUri = navPageUri;

            // Set the INavHost NavHostParent (probably a StackPanel)
            this.NavHostParent = parent;

            // Add a Click event handler to notify the NavHostParent to navigate
            this.Click += new RoutedEventHandler(OnClickHandler);

            /*
             * This pragma stops the compiler warning "Variable 'e' is delcared but never used
             */
            #pragma warning disable 0168
            // Attempt to apply the "GrayButtonStyle"
            try
            {
                this.Style = (Style)Inspire.App.Current.FindResource(styleName);
            }
            catch (ResourceReferenceKeyNotFoundException e)
            {
            }
            #pragma warning restore 0168
        }

        /// <summary>
        /// Extra Click RoutedEventHandler to notify pageIndex to navigate.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void OnClickHandler(object sender, RoutedEventArgs args)
        {
            this.NavHostParent.PropogateNavUp(this._NavPageUri);
        }
    }
}
